package com.ruoyi.finance.gift.protal;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.finance.gift.domain.SzGift;
import com.ruoyi.finance.gift.service.ISzGiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 打赏礼物Controller
 *
 * @author wangmh
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/protal/finance/gift")
public class AppSzGiftController extends BaseController {
    @Autowired
    private ISzGiftService szGiftService;

    /**
     * 查询打赏礼物列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SzGift szGift) {
        startPage();
        List<SzGift> list = szGiftService.selectSzGiftList(szGift);
        return getDataTable(list);
    }

    /**
     * 导出打赏礼物列表
     */
    @Log(title = "打赏礼物-数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SzGift szGift) {
        List<SzGift> list = szGiftService.selectSzGiftList(szGift);
        ExcelUtil<SzGift> util = new ExcelUtil<SzGift>(SzGift.class);
        return util.exportExcel(list, "打赏礼物数据");
    }

    /**
     * 获取打赏礼物详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(szGiftService.selectSzGiftById(id));
    }

    /**
     * 新增打赏礼物
     */
    @Log(title = "打赏礼物-新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzGift szGift) {
        return toAjax(szGiftService.insertSzGift(szGift));
    }

    /**
     * 修改打赏礼物
     */
    @Log(title = "打赏礼物-修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzGift szGift) {
        return toAjax(szGiftService.updateSzGift(szGift));
    }

    /**
     * 删除打赏礼物
     */
    @Log(title = "打赏礼物-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(szGiftService.deleteSzGiftByIds(ids));
    }
}
